import React, {Component} from 'react'
import PropTypes from 'prop-types'

export default class PropCheck extends Component {

  /* 
  类型检查: 检查属性值的类型和必要性
  */
  static propTypes = {
    name: PropTypes.string.isRequired,
    age: PropTypes.number.isRequired,
    wife: PropTypes.shape({
      name: PropTypes.string.isRequired,
      age: PropTypes.number.isRequired
    }).isRequired,
    likes: PropTypes.array
  }
  /* 指定非必要属性的默认值 */
  static defaultProps = {
    likes: ['台球', '乒乓球', '篮球']
  }

  render () {
    const { name, age, likes, wife} = this.props
    return <div>
      <h2>PropCheck-个人信息</h2>
      <p>姓名: {name}</p>
      <p>年龄: {age}</p>
      <p>老婆: {wife.name + ' : ' + wife.age}</p>
    	<p>爱好: {likes.join('-')}</p>
    </div>
  }
}



// function PropCheck(props) {
  
// }
// PropCheck.propTypes = {}
// PropCheck.defaultProps = {}